/**
 * 
 */
package com.sad.model;

import java.io.IOException;

import org.codehaus.jackson.map.ObjectMapper;

/**
 * 
 * @author zhaoqy
 * 
 */
public class SystemUser implements IModel {
	private static final long serialVersionUID = -1603528954541926320L;

	private String userId;
	private String userName;
	private String password;
	private String newPassword;
	/**
	 * 001 用户角色为系统维护员 010 用户角色为运行分析员 100 用户角色为业务分析员
	 */
	private String roleCode;
	private String roleName;
	private String description;

	private String[] roleCodes;

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String passWord) {
		this.password = passWord;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	/**
	 * @return the newPassword
	 */
	public String getNewPassword() {
		return newPassword;
	}

	/**
	 * @param newPassword
	 *            the newPassword to set
	 */
	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}

	/**
	 * @return the roleCode
	 */
	public String getRoleCode() {
		return roleCode;
	}

	/**
	 * @param roleCode
	 *            the roleCode to set
	 */
	public void setRoleCode(String roleCode) {
		this.roleCode = roleCode;
		this.roleCodes = this.roleCode.split(",");
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description
	 *            the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @return the roleName
	 */
	public String getRoleName() {
		return roleName;
	}

	/**
	 * @param roleName
	 *            the roleName to set
	 */
	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	/**
	 * 超级管理员
	 * 
	 * @return
	 */
	public boolean isAdmin() {

		for (String code : this.roleCodes) {
			if ("1".equals(code)) {
				return true;
			}
		}

		return false;
	}

	/**
	 * 运行分析员
	 * 
	 * @return
	 */
	public boolean isOperation() {
		for (String code : this.roleCodes) {
			if ("2".equals(code)) {
				return true;
			}
		}

		return false;
	}

	/**
	 * 业务分析员
	 * 
	 * @return
	 */
	public boolean isBusiness() {
		for (String code : this.roleCodes) {
			if ("3".equals(code)) {
				return true;
			}
		}

		return false;
	}
	
	/**
	 * 系统管理员
	 * @return
	 */
	public boolean isSystemManager() {
		for (String code : this.roleCodes) {
			if ("4".equals(code)) {
				return true;
			}
		}

		return false;
	}

	@Override
	public String toJson() {
		ObjectMapper objectMapper = new ObjectMapper();
		String json = "";
		try {
			json = objectMapper.writeValueAsString(this);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return json;
	}

}
